import NotFoundIndex from "../view/notfound/NotFoundIndex";
import LoginIndex from "../view/login/LoginIndex";
import { Navigate, useRoutes } from 'react-router-dom'

// * 导入所有router
const metaRouters = import.meta.glob("./modules/*.jsx", { eager: true });

// * 处理路由
export let routerArray = [];
Object.keys(metaRouters).forEach(item => {
    let route = metaRouters[item]
    Object.keys(route).forEach(v=> {
        routerArray = [...route[v], ...routerArray];
    })
});

export const rootRouter= [
    { path: '/', element: <Navigate to={'/home/index'} /> },
    {
        path: '/login',
        element: <LoginIndex />,
        meta: {
            requiresAuth: false,
            title: "登录页",
            key: "login"
        }},
        ...routerArray,
    { path: '*', element: <Navigate to={'/404'} /> }
]

const Router = () => {
    const routes = useRoutes(rootRouter);
    return routes;
};
export default Router;